package com.sinosoft.mcp.server.mysql.service;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MySQLService {

    @PersistenceContext
    private EntityManager entityManager;

    @Tool(description = "列出MySQL数据库中的表。")
    @Transactional
    public List<String> showTables() {
        String sql = "SHOW TABLES;";
        return entityManager.createNativeQuery(sql).getResultList();
    }
}
